<?php
class weatherProvinceComponents extends sfComponents
{

	public function executeProvinceWeatherBox() {
		$this->province = ProvincesPeer::retrieveByPK( $this->provinceId );
		$this->forecasts = TMDService::findInputSevenDaysForecastByProvince( array( 'provinceId' => $this->provinceId, 'language'=>'THAI' ) );
	}
	
	public function executeProvinceWeatherMenuBox() {
		$this->regions = TMDService::findAllGeographicRegions( array() );
	}
	
	public function executeProvinceWeatherDetailBox() {
		
		$c = new Criteria();
		$c->add( ProvincesPeer::IPROVINCE_ID, $this->provinceId );
		$province = ProvincesPeer::doSelectOne( $c );
		
		
		$stations = TMDService::findStationsByProince( array( "provinceId" => $province->getIprovinceId() ) );
		$datas = array();
		if( $stations && count( $stations ) > 0 ) {
			foreach( $stations as $station ) {
				$stationId = $station->getIstationId();
				$datas[$stationId] = TMDService::findLastWeatherProvince( array( "stationId" => $stationId ) );
			}
		}
		$this->stations = $stations;
		$this->province = $province;
		$this->datas = $datas;
		
		$longStays = TMDService::findWeeklyForecast( array( "provinceId" => $this->provinceId ) );
		$this->longStays = $longStays;
	}
}